package com.example.checkqufuface.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.checkqufuface.R;

import java.util.List;

public class SexKaAdapter extends RecyclerView.Adapter<SexKaAdapter.ViewHolder> {

    private Context context;
    private List<String> sexList;
    private SexClickListener sexClickListener;

    public SexKaAdapter(Context context, List<String> sexList) {
        this.context = context;
        this.sexList = sexList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_sex_ka, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {

        holder.sexShow.setText(sexList.get(position));
        holder.sexShow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sexClickListener.sexSelect(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return sexList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView sexShow;
        private final LinearLayout linearLayout;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            sexShow = itemView.findViewById(R.id.tv_sex_show);
            linearLayout = itemView.findViewById(R.id.ll_sex_selete);
        }
    }

    public interface SexClickListener{
        void sexSelect(int pos);
    }

    public void SetSexClickListener(SexClickListener clickListener){
        this.sexClickListener = clickListener;
    }
}
